﻿@inject NavigationManager NavigationManager
@inject IPopupService PopupService

<MDCard Class="message-info-card ps-4 pe-4 pt-3 pb-3 mb-3">
    <div style="display: flex; flex-direction: column;">
        <div class="mb-2" style=" display: flex;">
            <img class="elevation-2 me-3" src="@Model.Image"
                 style="height: 45px;width: 45px;border-radius: 50%;" />
            <div class="name-card">
                <div class="title-medium">@Model.Title</div>
                <div class="label-large">@Model.PostTime.ToString("yyy-MM-dd H:mm")</div>
            </div>
        </div>
        <div class="mb-2">
            <CnGalWebSite.Shared.MasaComponent.Shared.Components.Markdown.MarkdownViewTip Text="@Model.Text" IsNeedHighlight="false" />
        </div>
        <div style="display: flex; justify-content: flex-end;">
            @if (string.IsNullOrWhiteSpace(Model.Link) == false)
            {
                <CnGalWebSite.Components.Buttons.MasaButton Text="查看" OnClick="@(()=>NavigationManager.NavigateTo(Model.Link))" Small Rounded />
            }
            @if (CommentId != 0)
            {
                @if (IsReplying)
                {
                    <CnGalWebSite.Components.Buttons.MasaButton Text="取消回复" OnClick="OnUnReplyClick" Small Class="ms-3" Rounded />
                }
                else
                {
                    <CnGalWebSite.Components.Buttons.MasaButton Text="回复" OnClick="OnReplyClick" Small Class="ms-3" Rounded />
                }
            }

        </div>
        @if (IsReplying)
        {
            <CnGalWebSite.Shared.MasaComponent.PC.Comments.ReplyCommentTip ObjectId="@CommentId.ToString()" IsChild="true" Type="CommentType.ReplyComment" OnRefresh="OnRely" />
        }
    </div>
</MDCard>

@code {
    [Parameter]
    public CnGalWebSite.DataModel.Model.Message Model { get; set; }

    [Parameter]
    public long CommentId { get; set; }

    private bool IsReplying { get; set; }

    public void OnReplyClick()
    {
        IsReplying = true;
        StateHasChanged();
    }

    public void OnUnReplyClick()
    {
        IsReplying = false;
        StateHasChanged();
    }

    public async Task OnRely()
    {
        IsReplying = false;
        StateHasChanged();
        await PopupService.EnqueueSnackbarAsync(new SnackbarOptions
            {
                Type = AlertTypes.Success,
                Title = "回复成功",
                Timeout = 4000
            });
    }

}
